package hotciv.variants;

import hotciv.common.CityImpl;
import hotciv.common.ModifiableGame;
import hotciv.common.UnitImpl;
import hotciv.framework.*;
import hotciv.strategies.UnitActionStrategy;

public class GammaCivUnitActionStrategy implements UnitActionStrategy {
	
	@Override
	public void performUnitActionAt(ModifiableGame g, Position p) {
		UnitImpl u = (UnitImpl)g.getUnitAt(p);
	
		// change archer fortify-status
		if(u.getTypeString().equals(GameConstants.ARCHER)) {
			if(u.isMovable()) {
				// Only archer gets bonus defensive strength, while action is "fortify"
				u.setBonusDefensiveStrength(u.getDefensiveStrength());
				u.setMovable(false);
			} else {
				u.setBonusDefensiveStrength(0);
				u.setMovable(true);
			}
			
		}
		
		// add new city at position and remove settler
		if(u.getTypeString().equals(GameConstants.SETTLER)) {
			CityImpl c = new CityImpl(u.getOwner());
			g.addCityAt(c, p);
			g.removeUnitAt(p);
		}
	}

}
